<?php
/**
* oic_login.php
*/
include_once("config/config.inc.php");

if( $_POST['new_adj_oic'] && $_POST['new_adj_pwd'] ) {

	$usr = $_POST['new_adj_oic'];
	$pwd = $_POST['new_adj_pwd'];
	
	$sql = " select username from users where username='$usr' 
		and userpass='$pwd'  ";

		$res = mysql_query($sql) or die($sql);
	if(mysql_num_rows($res)) {
		session_start();
		$_SESSION['hotel']['oic_ok']=true;
		header("location: fdadj.php");
	}else{
		$msg = "Invalid OIC credentials.";
	}
}
?>
<html>
<body>
<link rel="stylesheet" type="text/css" href="../css/jquery.keypad.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/jquery.keypad.pack.js"></script>
<form method="post" action="oic_login.php">
<fieldset id="adjform"><legend>OIC Login Required</legend>
<?php echo $msg ?>
<table class="formtable">
<tr>
<td valign="top">Supervisor/OIC:</td>
<td>
Username:<br>
<?php
$sql = "select username, fullname from users where group_id=4";
$res = mysql_query($sql);
echo "<select name='new_adj_oic' id='new_adj_oic'>";
echo "<option ></option>";
while(list($usr,$full)=mysql_fetch_row($res))
{
	echo "<option value='$usr'>$full</option>";
}
echo "</select>";

?>
<input type="button" name="cmdFingerScan" id="cmdFingerScan" value="Finger Scan" /><br>
Password:<br>
<input type="password" name="new_adj_pwd" id="new_adj_pwd"  />
<input type="submit" value="Approve" name="cmdApprove" id="cmdApprove" />
</td>
</tr>
 
</tr>
</table>
</fieldset>
</form>
<script lang="javascript">
$(document).ready(function(){
	$("#cmdFingerScan").click(function(){
			$.post("oicfscan.php",{act:'scan', user: $("#new_adj_oic").val()});
			myinterval = setInterval(checkFScan, 3000);
		});

	$("#cmdApprove").click(function(){
			if($('#new_oic_pwd').val()=='') {
				//
				alert('Invalid input.');
			}else{
				/*
				$.post('oicvalidator.php',{usr: $("#new_adj_oic").val(), pwd:$('#new_adj_pwd').val()},
					function(resp) {
						if(resp==$("#new_adj_oic").val()) {
							$("#new_discount").val( $("#new_adjustment_amount").val() );
							recompute();
						}else{
							alert('Invalid input.');
						}
					}
				);
				*/
				return true;
			}
			return false;
		});
});
function checkFScan(){
	$.post("oicfscan.php",{act:'monitor', user: $("#new_adj_oic").val()},
	function(resp){
		if(resp.success==true) {
			$("#new_adj_pwd").val(resp.pass);
			//$("#cmdApprove").attr("enabled",true);
			$("#cmdApprove").trigger("click");
			clearInterval(myinterval);
		}
	},'json');
}
</script>
</body>
</html>
